import React from "react";
import { HintDialog } from "./../view/Dialog";
import { locationReplace } from "./../utils/LocationUtil";
import { ENTER } from "./../const/locations";
import { getID, getTOKEN } from "./../utils/StorageUtil";
import Config from "../Config";

/**
 * 界面组件父类。
 * 用户身份认证、基础方法。
 */
class BaseScreen extends React.Component {
  componentWillMount() {
    /**
     * 登录和注册等页面（不需要用户信息或者不涉及到用户信息的页面）需要实现isVerify方法并返回false
     * @type {boolean}
     */
    let verifyFlag = this.isVerify ? this.isVerify() : true;
    if (verifyFlag) {
      //检测是否存在用户id及系统d标记（wow）
      let TOKEN = getTOKEN();
      let TOKENFlag = TOKEN && TOKEN !== "null" && TOKEN !== "undefined";
      let sys = Config.SysFlag;
      let sysFlag = sys && sys !== "null" && sys !== "undefined";
      if (!TOKENFlag || !sysFlag) {
        locationReplace(ENTER);
      }
    }
   
  }


  constructor(props) {
    super(props);
  }

  getDefaultState() {
    return {
      defaultMsgDialog: false,
      defaultMsgDialogCon: ""
    };
  }

  /**
   * 渲染组件
   * @returns {*}
   */
  renderMsgDialog() {
    return (
      <HintDialog
        ref="dialog"
        operateText="确定"
        operateClick={() => {
          this.setState({
            defaultMsgDialog: false,
            defaultMsgDialogCon: ""
          });
        }}
      />
    );
  }

  /**
   * 弹出提示窗
   * @param msg
   */
  showMsgDialog(msg) {
    this.refs.dialog.setState({
      content: msg,
      visibility: true
    });
  }

  /**
   * 修改title
   * @param title
   */
  setTitle(title) {
    document.title = title;
  }
}

export default BaseScreen;
